package com.monkey.luffer.springboot.demo.basis.kcc.test.fight;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author jiahong.liu
 */
public class Poker {
    private final List<Card> cards;

    public void shuffle() {
        Collections.shuffle(cards);
    }

    public Card dealCard() {
        if (cards.isEmpty()) {
            throw new IllegalStateException("Deck is empty, cannot deal cards.");
        }
        return cards.remove(0);
    }

    public Poker() {
        cards = new ArrayList<>();
        for (Card.Suit suit : Card.Suit.values()) {
            for (Card.Rank rank : Card.Rank.values()) {
                cards.add(new Card(suit, rank));
            }
        }
    }

    public static class Card {
        public enum Suit {
            HEARTS, DIAMONDS, CLUBS, SPADES
        }

        @AllArgsConstructor
        @Getter
        public enum Rank {
            TWO("2"),
            THREE("3"),
            FOUR("4"),
            FIVE("5"),
            SIX("6"),
            SEVEN("7"),
            EIGHT("8"),
            NINE("9"),
            TEN("10"),
            JACK("J"),
            QUEEN("Q"),
            KING("K"),
            ACE("A"),
            S_JOKER("S_JOKER"),
            M_JOKER("JOKER"),;
            String value;
        }

        private final Suit suit;
        private final Rank rank;

        public Card(Suit suit, Rank rank) {
            this.suit = suit;
            this.rank = rank;
        }

        @Override
        public String toString() {
            return rank + " of " + suit;
        }
    }
}
